package com.tianlh.web;

import java.util.Arrays;
import java.util.List;

public class MyThreadPrinter2 implements Runnable {

    private String name;

    private Object pre;

    private Object self;

    private int count = 10;

    MyThreadPrinter2(String name, Object pre, Object self) {
        this.name = name;
        this.pre = pre;
        this.self = self;
    }

    @Override
    public void run() {
        while (count > 0) {
            synchronized (pre) {
                synchronized (self) {
                    System.out.print(name);
                    self.notifyAll();
                    count--;
                }
                try {
                    pre.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,4};
        List list = Arrays.asList(arr);
        System.out.println(list.size());
    }
}